package com.genshang.restaurant.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.genshang.restaurant.entity.Customerlist;
import com.genshang.restaurant.mapper.CustomerlistMapper;
import com.genshang.restaurant.result.LevelEnum;
import com.genshang.restaurant.result.ResultBody;
import com.genshang.restaurant.service.ICustomerlistService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Alex
 * @since 2020-09-26
 */
@Service
public class CustomerlistServiceImpl extends ServiceImpl<CustomerlistMapper, Customerlist> implements ICustomerlistService {

    @Override
    public Customerlist getCustomerlistById(String id) {
        QueryWrapper<Customerlist> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ID", id);
        return this.getOne(queryWrapper);
    }

    @Override
    public ResultBody addCustomer(String userName, String phone, String gender, String level, String birthday) {
        Customerlist customerlist = new Customerlist();
        customerlist.setNickname(userName);
        customerlist.setPhone(phone);
        customerlist.setBirthday(birthday);
        customerlist.setGender(gender);
        customerlist.setLevel(level);
        String levelName = LevelEnum.getLevelNameByLevel(level);
        customerlist.setLevelname(levelName);
        customerlist.setLeveluid("ababaaaaapR: com.restaurant.application.level.Level");
        customerlist.setCustomeruid("");
        customerlist.setId(System.currentTimeMillis() + "");
        customerlist.setCreatetime(System.currentTimeMillis());
        customerlist.setModifytime(System.currentTimeMillis());
        customerlist.setState("正常");
        return ResultBody.success(this.save(customerlist));
    }
}
